package top.yxqz.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * @author Mr.余
 * @date 2022/11/25
 * @package top.yxqz.session
 * session持久化
 */
@WebServlet("/demo4")
public class SessionDemo4  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession(true);
        String id = session.getId();
        System.out.println("sessionID:"+id);


        Cookie cookie   = new Cookie("JSESSIONID",id);
        cookie.setMaxAge(60*60*24*7);
        response.addCookie(cookie);
    }
}
